package com.springboot.demo.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class SingleThreadTest {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newSingleThreadExecutor();

        AtomicInteger atomicInteger = new AtomicInteger();

        executorService.submit(() -> {
            try {
                atomicInteger.set(1);
                System.out.println(atomicInteger.get());
            } catch (Exception e) {
                e.printStackTrace();
            }

        });
        executorService.submit(() -> {
            atomicInteger.compareAndSet(1, 2);
            System.out.println(atomicInteger.get()
            );
        });
        executorService.submit(() -> {
            atomicInteger.compareAndSet(2, 3);
            System.out.println(atomicInteger.get()
            );
        });
        executorService.submit(() -> {
            atomicInteger.compareAndSet(3, 4);
            System.out.println(atomicInteger.get()
            );
        });
    }
}
